package untitled14;

import java.awt.*;
import java.awt.image.BufferedImage;

import javax.swing.*;
import java.io.*;

public class Frame1 extends JFrame {

//  Image img=Toolkit.getDefaultToolkit().createImage(Map.e);
  public  Frame1(String s) {
/*try {
     RandomAccessFile ri=new RandomAccessFile("d:\\e.jpg","r");
     byte [] map=new byte[(int)ri.length()];
     ri.read(map,0,(int)ri.length());
     mmm=map;
     for (int i=0;i<map.length;i++)
      {
       System.out.print(map[i]+", ");
       if ((i%10)==0)
         System.out.println();

      }


   }
   catch (Exception ex) { System.out.println(ex);

   }

*/

  }
  public void paint(Graphics g){
	  
	int width = 512;
	int height = 512;

	String path = "e:/N20031223G062731.img";
	
	BufferedImage img = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
	
	try {
		
		int[] sample = GetData(path);
		img.getRaster().setSamples(0, 0, width, height,0, sample);
		
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} 
	  
    g.drawImage(img,0,0,512,512,this);

  }
  public  int[] GetData(String FileName) throws Exception {
		RandomAccessFile rFile = new RandomAccessFile(FileName, "r");
		
//		ArrayList<Short> arraylist = new ArrayList<Short>();
//		int[][] result = new int[512][512];
		int[] result = new int[512*512];
		long point = rFile.length() - 512*512*2;
		int i = 0, j = 0;
		rFile.seek(point);
		while (rFile.getFilePointer() < rFile.length()) {
			long p = rFile.getFilePointer();
			if (p < point)
				rFile.readByte();
			else {
//				result[i++] = rFile.readUnsignedShort();
//				result[i][j++] = rFile.readUnsignedShort();
				result[i++] = getByte(rFile.readByte(),rFile.readByte());
				}
			}

		rFile.close();
		return result;
	}
  public  int getByte(byte a,byte b){
		return (int) ((b& 0xFF)*256+ (a & 0xFF));	
	}
  public static void main(String[] args) {
    Frame1 frame1 = new Frame1("hello");
    frame1.setSize(600,600);
    frame1.setVisible(true);


  }
}